home *** CD-ROM | disk | FTP | other *** search
/ PC Format (UK) 188 / 01-04 PC Format 188 [2006-06] DVD side 1_.iso / DiscContents / Workshops / Workshops_Graphics / 3DCanvas / 3DCanvas.msi / Instal01.cab / _1D7AD0026AC04F1184B863BED733E65B < prev    next >
Text File  |  2002-02-17  |  6KB  |  203 lines

  1. Language = VBScript
  2.  
  3. '*********************************************************************************
  4. ' Purpose: Creates a Face
  5. '*********************************************************************************
  6.  
  7. Option Explicit          'require variable declarations
  8.  
  9. Sub Main (CanvasApp)
  10.  
  11.     Dim Scene            'The current active scene
  12.     Dim SceneRootGroup   'The root Group of the scene
  13.     Dim Group            'The Group for our object (face)
  14.     Dim Object           'The object we are creating (face)
  15.     Dim Face             'The face we are creating    
  16.     Dim GridOriginX      'The 3D Canvas Grid's Origin (x)
  17.     Dim GridOriginY      'The 3D Canvas Grid's Origin (y)
  18.     Dim GridOriginZ      'The 3D Canvas Grid's Origin (z)
  19.     Dim GridSize         'The 3D Canvas Grid's Size
  20.     Dim GridInterval     'The 3D Canvas Grid's Interval
  21.     Dim Points           'The user's desired # of points
  22.     Dim NumericPoints    'Points converted to a number
  23.     Dim FirstPointX      'First point in face
  24.     Dim FirstPointY      'First point in face
  25.     Dim FirstPointZ      'First point in face
  26.     Dim AxisX            'Axis to rotate the start position around
  27.     Dim AxisY            'Axis to rotate the start position around
  28.     Dim AxisZ            'Axis to rotate the start position around
  29.     Dim Point            'Point we are creating
  30.     Dim NewPointX        'Point to add
  31.     Dim NewPointY        'Point to add
  32.     Dim NewPointZ        'Point to add
  33.     Dim BoxMinX          'The Object's Bounding Box
  34.     Dim BoxMinY          'The Object's Bounding Box
  35.     Dim BoxMinZ          'The Object's Bounding Box
  36.     Dim BoxMaxX          'The Object's Bounding Box
  37.     Dim BoxMaxY          'The Object's Bounding Box
  38.     Dim BoxMaxZ          'The Object's Bounding Box
  39.     Dim Material         'The Face's Material
  40.  
  41.     'ask the user how many points s/he wants
  42.     Do
  43.         Points = InputBox("How many points would you like in the face?",,"4")
  44.  
  45.         'if they entered anything
  46.         If Points <> "" Then        
  47.             'they could have entered anything so ensure it is valid
  48.             On Error Resume Next
  49.             NumericPoints = clng(Points)
  50.             Err.Clear
  51.             On Error Goto 0
  52.  
  53.             'Let them know we had a problem
  54.             If NumericPoints < 3 Then
  55.                 Msgbox "3 is the minimum number of points", vbInformation
  56.             End If        
  57.         End if
  58.     Loop Until NumericPoints >= 3 Or Points = ""
  59.  
  60.     'If they entered anything continue
  61.     If Points <> "" Then
  62.  
  63.         'get the scene
  64.         Set Scene = CanvasApp.GetActiveScene
  65.  
  66.         'get the root Group
  67.         Set SceneRootGroup = Scene.GetRootGroup
  68.  
  69.         'create a Group for the object (face)
  70.         Set Group = Scene.CreateGroup
  71.  
  72.         'add it to the scene
  73.         SceneRootGroup.AddChild Group
  74.  
  75.         'give the Group a name - note that we can't do this
  76.         'until the Group is added to the scene
  77.         Group.SetName "Face Group"
  78.  
  79.         'create an object
  80.         Set Object = Scene.CreateObject()
  81.  
  82.         'add the face to the object
  83.         Set Face = Object.CreateFace
  84.  
  85.         'add a dummy normal to the object (we need one to add the points)
  86.         Object.AddNormal 0,0,-1
  87.  
  88.         'set the FirstPoint
  89.         FirstPointX = 0
  90.         FirstPointY = .5
  91.         FirstPointZ = 0
  92.  
  93.         'we're going to make an exception if they want four faces
  94.         'a quad will look wrong if we just rotate around a point
  95.         If NumericPoints = 4 Then
  96.             'add the quad points to the object
  97.             Object.AddPoint -.5,-.5,0
  98.             Object.AddPoint -.5,.5,0
  99.             Object.AddPoint .5,.5,0
  100.             Object.AddPoint .5,-.5,0
  101.  
  102.             'add the points and the normal to the face
  103.             Face.AddPointAndNormal 0,0
  104.             Face.AddPointAndNormal 1,0
  105.             Face.AddPointAndNormal 2,0
  106.             Face.AddPointAndNormal 3,0        
  107.         Else
  108.             'add the points to the object
  109.             For Point = 0 to NumericPoints - 1
  110.                 'rotate the FirstPoint to get a NewPoint
  111.                 CanvasApp.RotatePoint FirstPointX, FirstPointY, FirstPointZ, 0, 0, -1, 6.2831853 / NumericPoints * Point, NewPointX, NewPointY, NewPointZ
  112.  
  113.                 'add the NewPoint to the object
  114.                 Object.AddPoint NewPointX, NewPointY, NewPointZ
  115.  
  116.                 'add the point to the face
  117.                 Face.AddPointAndNormal Point, 0
  118.             Next
  119.         End if
  120.  
  121.         'Create an appropriate material for the face
  122.         Set Material = Scene.CreateMaterial
  123.  
  124.         'make it a nice color
  125.         Material.SetColor .894,.773,.788
  126.  
  127.         'set the default diffuse value
  128.         Material.SetDiffuse 60
  129.  
  130.         'set the default ambient value
  131.         Material.SetAmbient 20
  132.  
  133.         'apply the material to the face
  134.         Face.SetMaterial Material
  135.  
  136.         'add the object to the created Group
  137.         'this also triggers the update to the database
  138.         Group.AddObject Object
  139.  
  140.         'set the object name - note that we can't do this until
  141.         'the object is added to a Group
  142.         Object.SetName "Face"
  143.  
  144.         'Now that we know the size of the object let's set the position of the Group
  145.         'so the face is visible
  146.         
  147.         'get the 3D Canvs grid details
  148.         CanvasApp.GetGridDetails GridOriginX, GridOriginY, GridOriginZ, GridSize, GridInterval
  149.  
  150.         'get the object's dimensions
  151.         Object.GetBoundingBox BoxMinX, BoxMinY, BoxMinZ, BoxMaxX, BoxMaxY, BoxMaxZ
  152.  
  153.         'Center the Object's Group on the Scene and have the object sitting nicely
  154.         'on the surface
  155.         Group.SetPosition SceneRootGroup, 0, GridOriginX + GridSize / 2, GridOriginY - BoxMinY, GridOriginZ + GridSize /2
  156.  
  157.     End If    
  158. End Sub
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.